﻿using System.Web.UI.WebControls;
using Ue.Framework.Web;
using Ue.Framework.Web.WebControls;
using Ue.Infrastructure.Web.UI;
using Ue.Qcdz.Domain.Articles;
using System;

namespace Ue.Qcdz.UI.Controls
{
    public class ArticleShow : SkinnedControl
    {
        private Literal ltrTitle;
        private Literal ltrSubTitle;
        private Literal ltrSummary;
        private Literal ltrReference;
        private Literal ltrKeyword;
        private Literal ltrImageUrl;
        private Literal ltrContent;
        private Literal ltrEditor;
        private Literal ltrCreateOn;
        private Literal ltrRelevance;
        private Literal ltrClickCount;


        public ArticleShow()
        {

        }

        protected override string GetSkinFileName()
        {
            return string.Empty;
        }

        protected override void InitializeSkin(System.Web.UI.Control skin)
        {
             ltrTitle = skin.FindControl<Literal>("ltrTitle");
            ltrSubTitle = skin.FindControl<Literal>("ltrSubTitle");
            ltrSummary = skin.FindControl<Literal>("ltrSummary");
            ltrReference = skin.FindControl<Literal>("ltrReference");
            ltrKeyword = skin.FindControl<Literal>("ltrKeyword");
            ltrImageUrl = skin.FindControl<Literal>("ltrImageUrl");
            ltrContent = skin.FindControl<Literal>("ltrContent");
            ltrEditor = skin.FindControl<Literal>("ltrEditor");
            ltrCreateOn = skin.FindControl<Literal>("ltrCreateOn");
            ltrRelevance = skin.FindControl<Literal>("ltrRelevance");
            ltrClickCount = skin.FindControl<Literal>("ltrClickCount");
            //
            BindToControl();
        }

        private void BindToControl()
        {
            string key = Page.Request.GetQueryValue<string>("Id");
            Article model = ArticleService.GetArticle(new Guid(key));
            if (model != null)
            {
                model.SetClickCount();
                ArticleService.UpdateArticle(model);
                if (model == null) return;
                if (this.ltrTitle != null)
                    ltrTitle.Text = this.Page.Title = model.Title;
                if (this.ltrSubTitle != null)
                    ltrSubTitle.Text = model.SubTitle;
                if (this.ltrSummary != null)
                    ltrSummary.Text = model.Summary;
                if (this.ltrReference != null)
                    ltrReference.Text = model.Reference;
                if (ltrKeyword != null)
                    ltrKeyword.Text = Keyword = model.Keyword;
                if (ltrImageUrl != null)
                    ltrImageUrl.Text = model.ImageUrl;
                if (ltrContent != null)
                    ltrContent.Text = model.Content;
                if (ltrCreateOn != null)
                    ltrCreateOn.Text = model.CreateOn.ToShortDateString();
                if (ltrEditor != null)
                    ltrEditor.Text = model.Editor;
                if (ltrRelevance != null)
                    ltrRelevance.Text = model.Relevance;
                if (ltrClickCount != null)
                    ltrClickCount.Text = model.ClickCount.ToString();
            }
        }

        public string Keyword
        {
            private set;
            get;
        }
    }
}